<template>

  <div class="content-box">
    <nav-title title="离职审批" :routerLink="routerLink"/>
    <div class="regulations-box">
      <div class="title">基本信息</div>
      <v-wastage-info v-bind:baseInfo="baseInfo"></v-wastage-info>
    </div>
    <div class="regulations-box">
      <div class="title">详细信息</div>
      <v-wastage-detail v-bind:detailInfo="detailInfo"></v-wastage-detail>
    </div>

    <!-- 流程信息 -->
    <div class="regulations-box">
      <div class="title">流程信息</div>
      <div class="info-label">人力资源面谈</div>
      <div class="info-cell" v-show="actionReasonRule.isDisplay">
        <div class="label2"><span class="red">*</span>离职原因</div>
        <div class="value2">
          <group>
            <popup-radio placeholder="请选择" :options="reasonList" v-model="reason" @on-hide="getDetailReason" :readonly="!actionReasonRule.isEdit"></popup-radio>
          </group>
        </div>
      </div>
      <div class="info-cell" v-show="rsTerDetailRule.isDisplay">
        <div class="label2"><span class="red">*</span>离职详细原因</div>
        <div class="value2">
          <group>
            <popup-radio placeholder="请选择" :options="detailReasonList" v-model="detailReason" :readonly="!rsTerDetailRule.isEdit"></popup-radio>
          </group>
        </div>
      </div>

      <p class="info-cell clearfix" v-show="cRsnSummaryRule.isDisplay">
        <label class="info-label-title"><span class="red">*</span>离职原因总结</label>
      </p>
      <div class="info-label-text" v-show="cRsnSummaryRule.isDisplay">
        <textarea rows="5" v-model="cRsnSummary" :readonly="!cRsnSummaryRule.isEdit"></textarea>
      </div>

      <div class="info-cell" style="margin-top: 10px" v-show="cIsRehireRule.isDisplay">
        <div class="label2">今后是否建议录用</div>
        <div class="value2">
          <group>
            <popup-radio placeholder="请选择" :options="suggestList1" v-model="suggest1" :readonly="!cIsRehireRule.isEdit"></popup-radio>
          </group>
        </div>
      </div>

      <p class="info-cell clearfix" v-show="cBriefReasonRule.isDisplay">
        <label class="info-label-title"><span class="red">*</span>简短理由</label>
      </p>
      <div class="info-label-text">
        <textarea rows="5" v-model="cBriefReason" :readonly="!cBriefReasonRule.isEdit"></textarea>
      </div>


      <div class="info-label" v-show="wastageMoudules2">部门面谈</div>
      <p class="info-cell clearfix" v-show="cIntervwNotesRule.isDisplay">
        <label class="info-label-title">面谈记录</label>
      </p>
      <div class="info-label-text" v-show="cIntervwNotesRule.isDisplay">
        <textarea rows="5" v-model="cIntervwNotes" :readonly="!cIntervwNotesRule.isEdit"></textarea>
      </div>
      <div class="info-cell" v-show="cIsRehireDeptRule.isDisplay">
        <div class="label2">今后是否建议录用</div>
        <div class="value2">
          <group>
            <popup-radio placeholder="请选择" :options="suggestList2" v-model="suggest2" :readonly="!cIsRehireDeptRule.isEdit"></popup-radio>
          </group>
        </div>
      </div>

      <p class="info-cell clearfix" v-show="cBriefRsnDeptRule.isDisplay">
        <label class="info-label-title">简短理由</label>
      </p>
      <div class="info-label-text" v-show="cBriefRsnDeptRule.isDisplay">
        <textarea rows="5" v-model="cBriefRsnDept" :readonly="!cBriefRsnDeptRule.isEdit"></textarea>
      </div>

    </div>

    <!-- 流程图 -->
    <div class="regulations-box">
      <div class="title">流程图</div>
      <v-flow-charts :transNum="cTransactionNbr"></v-flow-charts>
    </div>

    <!-- 审批意见 -->
    <div class="regulations-box">
      <div class="info-label">审批意见</div>
      <div class="info-label-text">
        <textarea readonly rows="5" v-model="cComments"></textarea>
      </div>
    </div>

    <!-- 底部按钮：此页面不需要 -->
    <div style="height: 50px"></div>
  </div>

</template>

<script>
  import { Selector, Group, PopupPicker,PopupRadio  } from 'vux'
  import { getWastage,getWastageReason,getCompensateProcess,getWastageDetailReason,getFormalApprove } from '../../api/api'
  import vWastageInfo from '../formalStaff/wastageInfo'
  import vWastageDetail from '../formalStaff/wastageDetail2'
  import vFlowCharts from '../formalStaff/common/flowChart'
  import { json2Form } from '../../util/http'
  import { dateFormat } from 'vux'

  export default {
    components: {
      vWastageInfo,vWastageDetail,Selector, Group, PopupPicker,PopupRadio,vFlowCharts
    },
    created(){
      this.cTransactionNbr = this.$route.query.cTransactionNbr;
      if (this.$route.query.approved == '0') {
      this.routerLink = 'TodoList'
      } else if (this.$route.query.approved == '1') {
      this.routerLink = 'DoneList'
      } else {
      this.routerLink = 'MyApplication'
      }
      //离职审批信息
      this.getWastageInfo();
      //获取字典表信息
      this.getDic();
    },
    mounted(){

    },
    data(){
      return {

        baseInfo: {
          emplid: '',//员工ID
          nameDisplay: '',//姓名
          deptDescr: '',//部门
          rsFullName: '',
          jobcodeDescr: '',//岗位
          rsJobLevel: '',//职等
          lastHireDt: '',//入职日期
          cName: '',//带教人
          createdttm: '',//申请日期
          phone: '',//联系电话
        },
        detailInfo: {
          terminationDt: '',//离职日期
          cTerExplain: '',//离职原因说明
          cOtherExplain: '',//其他说明
          //离职日期
          terminationDtRule: {
            isDisplay: true,
            isEdit: false,
          },
          cTerExplainRule: {
            isDisplay: true,
            isEdit: false,
          },
          cOtherExplainRule: {
            isDisplay: true,
            isEdit: false,
          },
        },

        //离职原因总结
        cRsnSummaryRule: {
          isDisplay: true,
          isEdit: false,
        },
        //今后是否录用
        cIsRehireRule: {
          isDisplay: true,
          isEdit: false,
        },
        //简短理由
        cBriefReasonRule: {
          isDisplay: true,
          isEdit: false,
        },
        //离职原因
        actionReasonRule: {
          isDisplay: true,
          isEdit: false,
        },
        //离职详细原因
        rsTerDetailRule: {
          isDisplay: true,
          isEdit: false,
        },
        //面谈记录
        cIntervwNotesRule: {
          isDisplay: true,
          isEdit: false,
        },
        //今后是否建议录用
        cIsRehireDeptRule: {
          isDisplay: true,
          isEdit: false,
        },
        //简短理由2
        cBriefRsnDeptRule: {
          isDisplay: true,
          isEdit: false,
        },

        reasonList: [],
        reason: '',
        detailReasonList: [],
        detailReason: '',
        suggestList1: [{value: '是', key: 'Y'},{value: '否', key: 'N'}],
        suggest1: '',
        suggestList2: [{value: '是', key: 'Y'},{value: '否', key: 'N'}],
        suggest2: '',

        cBriefRsnDept: '',
        cIntervwNotes: '',
        cBriefReason: '',
        cRsnSummary: '',

        cApprovalSw: "",
        cDenySw: "",
        cPushbackAllSw: "",
        cAddSw: "",

        //按钮点击的参数
        cWfType: '',
        cTransactionNbr: '',
        cComments: '',

        authFileds: [],

        //人力资源面谈是否显示
        wastageMoudules1: false,

        //部门面谈
        wastageMoudules2: false,

      }
    },
    methods: {
      getDic(){
        //离职原因字典
        getWastageReason({setId: 'XC001'}).then(res=>{
          this.reasonList = [];
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.reasonList.push({value: res.retData[i].descr,key: res.retData[i].actionReson});
          }
        }
      }).catch(res=>{

        });


      },
      getDetailReason(){
        //离职详细原因字典
        getWastageDetailReason({actionReason: this.reason}).then(res=>{
          this.detailReasonList = [];
        if(res && res.retCode === '000000'){
          for(let i=0; i<res.retData.length; i++){
            this.detailReasonList.push({value: res.retData[i].descr,key: res.retData[i].rsTerDetail});
          }
        }
      }).catch(res=>{

        });
      },
      getWastageInfo(){
        let params = {
          cTransactionNbr: this.cTransactionNbr
        };
        getWastage(params).then(res=>{

          if(res && res.retCode === '000000'){
          this.baseInfo.emplid = res.retData.emplid;
          this.baseInfo.nameDisplay = res.retData.nameDisplay;
          this.baseInfo.deptDescr = res.retData.deptDescr;
          this.baseInfo.rsFullName =  res.retData.rsFullName;
          this.baseInfo.jobcodeDescr = res.retData.jobcodeDescr;
          this.baseInfo.rsJobLevel = res.retData.rsJobLevel;
          this.baseInfo.lastHireDt = res.retData.lastHireDt;
          this.baseInfo.cName = res.retData.cName;
          this.baseInfo.createdttm = res.retData.createdttm;
          this.baseInfo.phone = res.retData.phone;

          this.detailInfo.terminationDt = dateFormat(res.retData.terminationDt,"YYYY-MM-DD");
          this.detailInfo.cTerExplain = res.retData.cTerExplain;
          this.detailInfo.cOtherExplain = res.retData.cOtherExplain;

          this.cApprovalSw = res.retData.cApprovalSw;
          this.cDenySw = res.retData.cDenySw;
          this.cPushbackAllSw = res.retData.cPushbackAllSw;
          this.cAddSw = res.retData.cAddSw;

          this.cWfType = res.retData.cWfType;

          this.authFileds = res.retData.authFileds;
          for(let i=0; i<this.authFileds.length; i++){
            if(this.authFileds[i].fieldKey == 'terminationDt'){
              let tmd = this.authFileds[i].fieldValue;
              this.detailInfo.terminationDt = tmd;
              this.detailInfo.terminationDtRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'cTerExplain'){
              let cte = this.authFileds[i].fieldValue;
              this.detailInfo.cTerExplain = cte;
              this.detailInfo.cTerExplainRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'cOtherExplain'){
              let coe = this.authFileds[i].fieldValue;
              this.detailInfo.cOtherExplain = coe;
              this.detailInfo.cOtherExplainRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'cRsnSummary'){
              let crs = this.authFileds[i].fieldValue;
              this.cRsnSummary = crs;
              this.cRsnSummaryRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'cIsRehire'){
              if(this.authFileds[i].fieldValue == 'Y'){
                this.suggest1 = 'Y';
              }else{
                this.suggest1 = 'N';
              };
              this.cIsRehireRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'cBriefReason'){
              let cbr = this.authFileds[i].fieldValue;
              this.cBriefReason = cbr;
              this.cBriefReasonRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'actionReason'){
              let areason = this.authFileds[i].fieldValue.split(",");
              this.reasonList.push({value: ''+areason[1],key:areason[0]});
              this.reason = areason[0];
              this.actionReasonRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'rsTerDetail'){
              let rtd = this.authFileds[i].fieldValue.split(",");
              this.detailReasonList.push({value: ''+rtd[1],key:rtd[0]});
              this.detailReason = rtd[0];
              this.rsTerDetailRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'cIntervwNotes'){
              let cin = this.authFileds[i].fieldValue;
              this.cIntervwNotes = cin;
              this.cIntervwNotesRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'cIsRehireDept'){
              if(this.authFileds[i].fieldValue == 'Y'){
                this.suggest2 = 'Y';
              }else{
                this.suggest2 = 'N';
              };
              this.cIsRehireDeptRule.isDisplay = this.authFileds[i].isDisplay;
            }else if(this.authFileds[i].fieldKey == 'cBriefRsnDept'){
              let cbrd = this.authFileds[i].fieldValue;
              this.cBriefRsnDept = cbrd;
              this.cBriefRsnDeptRule.isDisplay = this.authFileds[i].isDisplay;
            }

          }

          if(this.actionReasonRule.isDisplay || this.rsTerDetailRule.isDisplay
            || this.cRsnSummaryRule.isDisplay || this.cIsRehireRule.isDisplay
            || this.cBriefReasonRule.isDisplay) {
            this.wastageMoudules1 = true;
          }

          if(this.cIntervwNotesRule.isDisplay || this.cIntervwNotesRule.isDisplay
            || this.cIsRehireDeptRule.isDisplay || this.cBriefRsnDeptRule.isDisplay) {
            this.wastageMoudules2 = true;
          }

        }else{
          this.$vux.alert.show({
            title: '',
            content: res.retMsg
          })
        }
      }).catch (res=>{
          this.$vux.alert.show({
          title: '警告',
          content: '网络异常，请稍后重试'
        })
      })
      }
    }
  }
</script>
<style type="text/scss" lang="scss">
  @import '../../styles/staff.scss'
</style>
